<?php

namespace App\Models\Open;

use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Rennokki\QueryCache\Traits\QueryCacheable;

class MicroApp extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'micro_apps';

    protected $fillable = ['access_token', 'expire_time'];

    use QueryCacheable;

    protected $cacheFor = 3600;
    protected static $flushCacheOnUpdate = true;

    public function adminUser(): BelongsTo
    {
        return $this->belongsTo(Administrator::class );
    }

    public function sysAccount(): BelongsTo
    {
        return $this->belongsTo(SysAccount::class, 'sys_account_id' );
    }

    public function apiInfos(): BelongsToMany
    {
        return $this->belongsToMany(ApiInfo::class, 'micro_app_api_info');
    }

}
